﻿using System;
using System.IO;
using SDT.CNFSystem;

namespace SDT.CrawlSystem.Servers
{
    /// <summary>
    /// Written by TungNX
    /// </summary>
    internal class Global
    {
        #region Properties from config file
        private ICnfReader cfgReader = null;

        public int Interval
        {
            get
            {
                lock (instance)
                {
                    try { return Convert.ToInt32(cfgReader["Interval"]); }
                    catch { return 10000; }
                }
            }
        }

        public int WorkUnitInterval
        {
            get
            {
                lock (instance)
                {
                    try { return Convert.ToInt32(cfgReader["WorkUnitInterval"]); }
                    catch { return 1500; }
                }
            }
        }

        public string LogFile
        {
            get
            {
                lock (instance)
                    return cfgReader["LogFile"];
            }
        }

        #region Folders
        public string DataFolder
        {
            get
            {
                lock (instance)
                    return cfgReader["DataFolder"];
            }
        }

        public string CacheFolder
        {
            get
            {
                lock (instance)
                    return cfgReader["CacheFolder"];
            }
        }
        #endregion

        public string Domain
        {
            get
            {
                lock (instance)
                    return cfgReader["Domain"];
            }
        }

        public string User
        {
            get
            {
                lock (instance)
                    return cfgReader["User"];
            }
        }

        public string Pass
        {
            get
            {
                lock (instance)
                    return cfgReader["Pass"];
            }
        }

        public string[] DataFiles
        {
            get
            {
                try
                {
                    return Directory.GetFiles(DataFolder, "*.url.channel.xml");
                }
                catch { }

                return new string[] { };
            }
        }
        #endregion

        private Global() { cfgReader = new CnfReader(); }

        private static Global instance = new Global();
        internal static Global Instance
        {
            get { lock(instance) return Global.instance; }
        }
    }
}